# 教案管理平台 Makefile

.PHONY: help install dev build start stop clean logs

# 默认目标
help:
	@echo "教案管理平台 - 可用命令:"
	@echo "  install    - 安装依赖"
	@echo "  dev        - 启动开发环境"
	@echo "  build      - 构建项目"
	@echo "  start      - 启动生产环境"
	@echo "  stop       - 停止服务"
	@echo "  clean      - 清理资源"
	@echo "  logs       - 查看日志"
	@echo "  test       - 运行测试"

# 安装依赖
install:
	@echo "安装前端依赖..."
	cd frontend && pnpm install
	@echo "安装后端依赖..."
	cd backend && pnpm install
	@echo "依赖安装完成!"

# 开发环境
dev:
	@echo "启动开发环境..."
	docker-compose -f docker-compose.dev.yml up -d
	@echo "开发环境已启动!"
	@echo "前端: http://localhost:3000"
	@echo "后端: http://localhost:3001"
	@echo "MongoDB: mongodb://localhost:27018"

# 构建项目
build:
	@echo "构建项目..."
	cd frontend && npm run build
	cd backend && npm run build
	docker-compose build
	@echo "构建完成!"

# 生产环境
start:
	@echo "启动生产环境..."
	docker-compose up -d
	@echo "生产环境已启动!"

# 停止服务
stop:
	@echo "停止服务..."
	docker-compose down
	docker-compose -f docker-compose.dev.yml down
	@echo "服务已停止!"

# 清理资源
clean: stop
	@echo "清理Docker资源..."
	docker system prune -f
	docker volume prune -f
	@echo "清理完成!"

# 查看日志
logs:
	docker-compose logs -f

# 运行测试
test:
	@echo "运行前端测试..."
	cd frontend && npm run test
	@echo "运行后端测试..."
	cd backend && npm run test

# 数据库操作
db-reset:
	@echo "重置数据库..."
	docker-compose exec mongodb mongo lesson-plan --eval "db.dropDatabase()"
	@echo "数据库已重置!"

# 备份数据库
db-backup:
	@echo "备份数据库..."
	docker-compose exec mongodb mongodump --db lesson-plan --out /tmp/backup
	docker cp lesson-plan-mongo:/tmp/backup ./backup/$(shell date +%Y%m%d_%H%M%S)
	@echo "数据库备份完成!"